package org.smr.ministore.entities.validator.concre;

import org.apache.commons.collections.CollectionUtils;
import org.blade.entities.base.BizEntity;
import org.smr.ministore.entities.validator.OperationValidator;

import java.util.List;
import java.util.Objects;

public class ReferenceValidator<T extends BizEntity<Long>> implements OperationValidator<T>  {

    private OperationValidator operationValidator;

    List<T> references;

    @Override
    public boolean validate() {

        if(CollectionUtils.isEmpty(references)){
            if(Objects.isNull(operationValidator)){
                return true;
            }
            if(operationValidator.validate()){
                return true;
            }
        }
        return false;
    }

    @Override
    public void setValidateData(List<T> validateData) {
        this.references = validateData;
    }

    @Override
    public void setValidator(OperationValidator operationValidator) {
        this.operationValidator = operationValidator;
    }

}
